#include "bsp_shell.h"
#include "shell_port.h"
#include "bsp_crc.h"
#include "bsp_rtc.h"

static void ps(void){
	char tx_buf[256] = {0};
	vTaskList(tx_buf);
	debug_printf("%s\r\n",tx_buf);
}
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC),ps,ps,"show task msg");

static int gac(int argc, char *argv[]){
	uint32_t crc_value = 0;
	if(argc == 2){
		crc_value = crc32_check(~crc_value,(uint8_t *)(0x08000000),atoi(argv[1]) - 4);
		debug_printf("Get App CRC = %x\r\n",crc_value);
	}
	return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),gac,gac,"get app crc");

static int set_rtc(int argc, char *argv[]){
	if(argc == 8){
		bsp_set_rtc_date_time((uint8_t)atoi(argv[1]),(uint8_t)atoi(argv[2]),(uint8_t)atoi(argv[3]),(uint8_t)atoi(argv[4]),(uint8_t)atoi(argv[5]),(uint8_t)atoi(argv[6]),(uint8_t)atoi(argv[7]));
		debug_printf("set rtc time ok\r\n");
	}
	else{
		debug_printf("set rtc time error = %d \r\n",argc);
	}
	return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),set_rtc,set_rtc,"set rtc time");